﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CNav.Common;
using CNav.DataEntity;
using CNav.Domain.Admin;

namespace CNav.Business.Services
{
    public interface IConfigurationService
    {
        ResponseData<FormConfiguration> GetFormConfigurationForStage(Common.Stage stage);
    }

    public class ConfigurationService : ServiceBase, IConfigurationService
    {
        public ResponseData<FormConfiguration> GetFormConfigurationForStage(Common.Stage stage)
        {
            var stageName = stage.ToString();
            var response = new ResponseData<FormConfiguration>();
            var result = Context.Get<FormConfigurationDto>(f => f.Stage == stageName).Include(f => f.Form).ToList().FirstOrDefault();

            if (result != null)
            {
                response.Data = new FormConfiguration
                {
                    ID = result.ID,
                    Stage = result.Stage,
                    FormID = result.FormID ?? 0,
                    FormName = result.Form != null ? result.Form.Name : string.Empty
                };
                return response;
            }

            response.Error = new[] { "Invalid stage" };
            return response;
        }
    }
}
